package com.cube.dp.cor.wrapper;

import com.cube.dp.cor.context.TransformContext;
import com.cube.dp.cor.filter.TransformFilter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;

/**
 * @author cube.li
 * @date 2021/12/23 17:40
 * <p>
 * 为TransformFilter赋予名称的包装器
 */
@Slf4j
public class NamingTransformFilterWrapper implements TransformFilterWrapper {

    private final TransformFilter delegate;

    private final String name;

    public NamingTransformFilterWrapper(TransformFilter delegate, String name) {
        Assert.notNull(delegate, "TransformFilter delegate must be not null");
        Assert.notNull(name, "TransformFilter delegate name must be not null");
        this.delegate = delegate;
        this.name = name;
    }

    @Override
    public void doFilter(TransformContext context) {
        log.debug("过滤器{}执行中...", name);
        delegate.doFilter(context);
    }

    @Override
    public TransformFilter getDelegate() {
        return this.delegate;
    }
}
